import { dom } from './dom.js'

export const _tree = (treeData = [], render, levelLimited = -1) => {

    let fn = (treeData, render, level) => {
        let items = []
        treeData.forEach(t => {
            let title = render ? render(t) : t.title
            // let title =t.title
            let children = [title]
            if (levelLimited == -1 || level < levelLimited) {
                if (t.children) {
                    children.push(fn(t.children, render, level + 1))
                }
            }

            items.push(dom.li(children))
        })
        let ul = dom.ul(items)
        return ul
    }

    return fn(treeData, render, 0)

}